﻿using Nectar.DAL.Common;
using P2PWeb.Common;
using P2PWeb.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace P2PWeb.Controllers
{
    [AccountAuthorize(AccountType.Admin, AccountType.LookThrough, AccountType.User, AccountType.Agent)]
    public class MyLendsController : BaseController
    {
        public ActionResult Index(int pageIndex = 1)
        {

            using (var context = new Repository<P2PModelContainer>())
            {
                Pager<Flight> pager = new Pager<Flight>();
                pager.CurrentPageIndex = pageIndex; 
                QueryParameter[] pageParameters = pager.GetQueryParameters()
                    .Union(new[] { new QueryParameter() { Name = "AccountID", Value = CurrentUserInfo.ID } }).ToArray();
                pager.Items = context.GetListOf<Flight>(" o.AccountID=@AccountID order by o.CreationTime desc Skip @Skip Limit @Limit", pageParameters.ToArray(),
                   new List<string>(new[] { "Campaign" }));
                pager.TotialItemsCount = context.GetListOf<Flight>("o.AccountID=@AccountID", new[] { new QueryParameter() { Name = "AccountID", Value = CurrentUserInfo.ID }}).Count;
                var aa = pager.TotialPaqgerCount;
                ViewData["curAccount"] = CurrentUserInfo;
                if (Request.IsAjaxRequest())
                {
                    return PartialView("MyLendsAjax", pager);
                }
                return View(pager);
            }
        }
    }
}
